package com.tbsoft.ehr.service.department;

import java.util.List;

import com.tbsoft.ehr.dao.department.DepartmentDao;
import com.tbsoft.ehr.dao.staffFile.StaffFileDao;
import com.tbsoft.ehr.model.Department;

public class DepartmentServiceImpl implements DepartmentService {

	private DepartmentDao departmentDao;
	private StaffFileDao staffFileDao;

	public DepartmentDao getDepartmentDao() {
		return departmentDao;
	}

	public void setDepartmentDao(DepartmentDao departmentDao) {
		this.departmentDao = departmentDao;
	}

	public StaffFileDao getStaffFileDao() {
		return staffFileDao;
	}

	public void setStaffFileDao(StaffFileDao staffFileDao) {
		this.staffFileDao = staffFileDao;
	}

	public Department addDepartment(Department d) {
		return this.getDepartmentDao().saveOrUpdate(d);
	}

	public Department getDeptById(String id) {
		return this.getDepartmentDao().getDepartmentById(id);
	}

	public Department getDeptByName(String name) {
		List<Department> depts = this.getDepartmentDao().getDepartmentByName(name);
		if (depts != null && depts.size() > 0) {
			return depts.get(0);
		}
		return null;
	}

	public List<Department> getAllDepts() {
		return this.getDepartmentDao().getAllDepartments();
	}

	@Override
	public void deleteDepartment(Department d) {
		this.getStaffFileDao().updateDepartment(d.getId());
		this.getDepartmentDao().logicDelete(Department.class, d.getId());
	}

}
